package vincent.com.layouttest;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import vincent.com.layouttest.view.ColorStatusBarLayout;

/**
 * Created by chenzhengwen on 2015/5/19.
 */
public abstract class ColorStatusActivity extends ActionBarActivity {
    private ColorStatusBarLayout mContainer;
    private RelativeLayout mRealContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_color_status);

        mContainer = (ColorStatusBarLayout)findViewById(R.id.container);
        mRealContainer = (RelativeLayout)findViewById(R.id.content);

        if(Build.VERSION.SDK_INT >= 19){
            mContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            setStatusbarTransparent();

            mContainer = (ColorStatusBarLayout)findViewById(R.id.container);
            mContainer.setPadding(0, getStatusBarHeight(), 0, 0);
        }

        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        String title = getToolbarTitle();
        if(!TextUtils.isEmpty(title)){
            toolbar.setTitle(title);
        }

        setSupportActionBar(toolbar);

        onCreateView(mRealContainer);
    }

    public int getStatusBarHeight(){
        int height = 0;
        int resId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        height = getResources().getDimensionPixelSize(resId);

        return height;
    }

    private void setStatusbarTransparent(){
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    public abstract View onCreateView(ViewGroup rootView);

    public String getToolbarTitle(){
        return null;
    }

    protected ViewGroup getRootView(){
        return mContainer;
    }
}
